#ifndef _OGLUTILS_H
#define _OGLUTILS_H

#include <gl/GL.h>
#include <gl/GLU.h>
#include <glut.h>

namespace OGLUtils
{
	static void glutBitmapString(float x, float y, float z, void *font, char *string) {  
		char *c;
		glRasterPos3f(x, y,z);
		for (c=string; *c != '\0'; c++) {
			glutBitmapCharacter(font, *c);
		}
	}

	static void glutStrokeFontString(float x, float y, float z,	void *font,	char *string) {  
		char *c;
		glPushMatrix();
		glTranslatef(x, y,z);
		for (c=string; *c != '\0'; c++) {
			glutStrokeCharacter(font, *c);
		}
		glPopMatrix();
	}

	static void drawAxis(float lineLength, float lineWidth)
	{
		glPushMatrix();
			glLineWidth(lineWidth);

			glPushMatrix();
				glColor3f(1.0f,0.0f,0.0f);
				OGLUtils::glutBitmapString(lineLength,0.1f,0.0f,GLUT_BITMAP_TIMES_ROMAN_10,"+ X");
				glBegin(GL_LINES);
					glVertex3f(0.0f,0.0f,0.0f);
					glVertex3f(lineLength,0.0f,0.0f);
				glEnd();
				glTranslatef(lineLength,0.0f,0.0f);
				glPushMatrix();
				glRotatef(90.0f,0,1,0);
				glutSolidCone(0.03,.1,20,1);
				glPopMatrix();
			glPopMatrix();

			glPushMatrix();
				glColor3f(0.0f,1.0f,0.0f);
				OGLUtils::glutBitmapString(0,lineLength,0,GLUT_BITMAP_TIMES_ROMAN_10,"+ Y");
				glBegin(GL_LINES);
					glVertex3f(0.0f,0.0f,0.0f);
					glVertex3f(0.0f,lineLength,0.0f);
				glEnd();
				glTranslatef(0.0f,lineLength,0.0f);
				glPushMatrix();
				glRotatef(-90.0f,1,0,0);
				glutSolidCone(0.03,.1,20,1);
				glPopMatrix();
			glPopMatrix();

			glPushMatrix();
				glColor3f(0.0f,0.0f,1.0f);
				OGLUtils::glutBitmapString(0,0,lineLength,GLUT_BITMAP_TIMES_ROMAN_10,"+ Z");
				glBegin(GL_LINES);
					glVertex3f(0.0f,0.0f,0.0f);
					glVertex3f(0.0f,0.0f,lineLength);
				glEnd();
				glTranslatef(0.0f,0.0f,lineLength);
				glutSolidCone(0.03,.1,20,1);
			glPopMatrix();

		glPopMatrix();
	}
	static void drawGrid(float grid_lineWidth, 
		float grid_min, float grid_max, float grid_step,
		float r, float g, float b)
	//	bool gridXY_draw, float gridXY_lineWidth, float gridXY_min, float gridXY_max, float gridXY_step,
	//	bool gridYZ_draw, float gridYZ_lineWidth, float gridYZ_min, float gridYZ_max, float gridYZ_step)
	{
		/* Render grid over 0..rows, 0..columns. */
		glPushMatrix();
		//glBegin(GL_LINES);
		///* Horizontal lines. */
		//for (int i=0; i<=rows; i++) {
		//	glVertex3f(0, i);
		//	glVertex3f(columns, i);
		//}
		///* Vertical lines. */
		//for (i=0; i<=columns; i++) {
		//	glVertex3f(i, 0);
		//	glVertex3f(i, rows);
		//}
		//glEnd();
		float tmp;
		/* Draw Grid */
		glLineWidth (grid_lineWidth);
		glColor3f (0.50, .50, 0.50);
		glBegin (GL_LINES);
		for (tmp = grid_min; tmp <= grid_max; tmp += grid_step)
		{
			glVertex3f (tmp, 0.00, grid_min);
			glVertex3f (tmp, 0.00, grid_max);
		};
		glEnd ();

		glBegin (GL_LINES);
		for (tmp = grid_min; tmp <= grid_max; tmp += grid_step)
		{
			glVertex3f (grid_min, 0.0, tmp);
			glVertex3f (grid_max, 0.0, tmp);
		};
		glEnd ();
		glPopMatrix();
	}


}

#endif // OGLUTILS